using System;
using System.Collections;
using UnityEngine;
using UnityEngine.UI;
using DG.Tweening;

namespace Hotran.UI
{
    public class SceneTransition : MonoBehaviour
    {
        private Image image;

        [Tooltip("������ʼʱ����")]
        [SerializeField]
        private bool transitOnStart = false;

        [SerializeField]
        private float transitionTime = 1f;


        private void Awake()
        {
            image = GetComponent<Image>();
            image.enabled = true;
        }

        // Start is called before the first frame update
        void Start()
        {
            if (transitOnStart) FadeIn();
        }

        public void FadeIn(Action actionOnFaded = null) => DoFade(0f, actionOnFaded);

        public void FadeOut(Action actionOnFaded = null) => DoFade(1f, actionOnFaded);

        private void DoFade(float targetAlpha, Action actionOnFaded) => 
            image.DOFade(targetAlpha, transitionTime).OnComplete(() => actionOnFaded?.Invoke());
    }
}